/******************************
 Description
	Provides the common validating function.

Dependency
	Date.js
*******************************/



    /***************************************************************
        Constructor
    ****************************************************************/
function Validator(){}


    /***************************************************************
        Public methods
    ****************************************************************/

Validator.prototype.isChinese 		= validator_js_isChinese
Validator.prototype.isEmail 		= validator_js_isEmail
Validator.prototype.isHkPhone 		= validator_js_isHkPhone
Validator.prototype.isHkId 			= validator_js_isHkId
Validator.prototype.isEmptyString 	= validator_js_isEmptyString
Validator.prototype.isDate 			= validator_js_isDate
Validator.prototype.isTime12		= validator_js_isTime12
Validator.prototype.isTime24		= validator_js_isTime24
Validator.prototype.matchTimePattern= validator_js_matchTimePattern
Validator.prototype.isDateDDMMYYYY	= validator_js_isDateDDMMYYYY
Validator.prototype.isInteger		= validator_js_isInteger
Validator.prototype.isNumeric		= validator_js_isNumeric
Validator.prototype.isNumber		= validator_js_isNumber
Validator.prototype.isFloat			= validator_js_isFloat
Validator.prototype.isLeapYear		= validator_js_isLeapYear
Validator.prototype.isWithInRange	= validator_js_isWithInRange
Validator.prototype.isBankAccountNo	= validator_js_isBankAccountNo
Validator.prototype.isArrayEquals	= validator_js_isArrayEquals
Validator.prototype.isDateGreater	= validator_js_isDateGreater
Validator.prototype.isDateGreater_DDMMYYYY	= validator_js_isDateGreater_DDMMYYYY
Validator.prototype.isContainLeapDay		= validator_js_isContainLeapDay
Validator.prototype.checkUid		= validator_js_checkUid
Validator.prototype.allowFileObj		= validator_js_allowFileObj

/**
* Check whether it contains chinese character. By checking the ascii code out of 32 to 126 for each character.
* @param	input 	input of the string
* @return	true 	chinese, false - not a chinese
**/

function validator_js_isChinese(input)
{
	var FUNCTION_NAME = "isChinese()";
	var isValid = false;
	try {
		// Loop each character to check whether it contains non-english ascii code
	    for ( var i = 0 ; i < input.length ; i++) {
	        var code = input.charCodeAt(i);
	        if (code < 32 || code > 126) {
	            isValid = true;
	        }
	    }
	} catch  (objException){
		alert("Javascript Exception [" + this.FILE_NAME + ", " + FUNCTION_NAME + "]: " + objException + ".");
		return false;
	}
	return isValid;
}
/**
* Check if it is valid email address Format [all English character A-Z or number 0-9 or "_" or "-" or "."] @ [all English character A-Z or number 0-9 or "_" or "-" or "."].[all English character A-Z or number 0-9 with the length of 2-4]
* @param 	string		the input value.
* @return 	boolean		true: valid email address, false:otherwise.
**/
function validator_js_isEmail(input) {
	var FUNCTION_NAME = "isEmail()";
	var isValid = false;
	try {
		//allow pass if null
		if ( input == "" ) {
			isValid = true;
		} else {
			// use regular expression to check the format
			var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			isValid = filter.test(input);
		}
	} catch  (objException){
		alert("Javascript Exception [" + this.FILE_NAME + ", " + FUNCTION_NAME + "]: " + objException + ".");
		return false;
	}
	return isValid;
}
/**
* Check if it is valid phone number.
* @param 	string		the input value.
* @return 	boolean		true: valid phone number, false:otherwise.

**/
function validator_js_isHkPhone(input) {

	var FUNCTION_NAME = "isHKPhone()";
	var isValid = false;

	try {
		var filter  = /^[0-9]{8}$/;
		//allow pass if null
	    if (input == "") {
	    	isValid = true;
	    } else {
	    	isValid = filter.test(input);
		}

	} catch  (objException){
		alert("Javascript Exception [" + this.FILE_NAME + ", " + FUNCTION_NAME + "]: " + objException + ".");
		return false;
	}
	return isValid;

}

/**
* Check if it is valid HK Id. (not use for taiwan)
* @param 	string		the input value.
* @return 	boolean		true: valid HK Id, false:otherwise.
**/
// modified by Victor on 12Nov2003
function validator_js_isHkId(no) {

	var FUNCTION_NAME = "isHKId()";
	var isValid = false;

	try {

		var idno = no.toUpperCase();

		// use the regular expression to check the format
		var filter  = /^[A-Z]{1,2}[0-9]{6}\([A0-9]\)$/;
		var filter2  = /^[A-Z]{1,2}[0-9]{6}[A0-9]$/;

		if (!filter.test(idno) && !filter2.test(idno) ) {
			isValid = false;
		}
		// continus to check
		if ( isValid ) {

			blanketIndex = no.indexOf("(");

			if ( blanketIndex < 0 ) {
				data = idno.substring(0,idno.length-1)
				lastDigit = idno.substring(idno.length-1,idno.length)
			}
			else {
				data = idno.substring(0,blanketIndex)
				//	alert("data =" + data);
				lastDigit = idno.substring(blanketIndex+1, blanketIndex +2)
			}

			if (lastDigit == "A")	{ lastDigit = 10; }
			//	alert("lastDigit =" + lastDigit);
			var sum = 0;
			if (no.length == 10 || no.length ==8) { //handle 1 char's ID no
				sum+= 36 * 2 ;//extract " " char's value
				sum += (parseInt(data.charCodeAt(0)) - 55) * 3;
				for (i = 1 ; i < data.length ; i++) {
					sum += parseInt(data.charAt(i)) * (i + 3);
				}

			}
			else if (no.length == 11) {//handle 2 char's ID no
				sum += (parseInt(data.charCodeAt(0)) - 55) * 2;
				sum += (parseInt(data.charCodeAt(0)) - 55) * 3; //extract 2nd char's value

				for (i = 2 ; i < data.length ; i++) {
					sum += parseInt(data.charAt(i)) * (i + 2);
				}

			}
			if (sum % 11 != lastDigit) {
		        isValid = false;
		    }
    	}
	} catch  (objException){
		alert("Javascript Exception [" + this.FILE_NAME + ", " + FUNCTION_NAME + "]: " + objException + ".");
		return false;
	}
	return isValid;

}
/**
* Check if it is empty string.
* @param 	string		the input value.
* @return 	boolean		true: empty string or null, false:otherwise.
**/
function validator_js_isEmptyString(input){

	var FUNCTION_NAME = "isEmptyString()";
	var isValid = false;
	try {

		var tmpStr = input;
		// Trim the input
		tmpStr = tmpStr.replace( /^\s+/g, "" );// strip leading
  		tmpStr.replace( /\s+$/g, "" );// strip trailing

		if (tmpStr=="") {
			isValid = true;
		} else {
			isValid = false;
		}

	} catch  (objException){
		alert("Javascript Exception [" + this.FILE_NAME + ", " + FUNCTION_NAME + "]: " + objException + ".");
		return false;
	}
	return isValid;

}
/**
* Check if it is valid date..
* @param 	int			the day.
* @param 	int			the month.
* @param 	int			the year.
* @return 	boolean		true: valid date, false:otherwise.

**/
function validator_js_isDate(day, month, year) {

	var FUNCTION_NAME = "isDate()";
	var isValid = true;

	try {
		// check month value with the range
		if (month < 1 || month > 12) {
			isValid = false;
		}
		// check day value with the range
		if (day < 1 || day > 31) {
			isValid = false;
		}
		// check day value with the range for the month with 31 days
		if ((month == 4 || month == 6 || month == 9 || month == 11) &&
			(day == 31)) {
			isValid = false;
		}
		// check day value with the range for the month with 28 days or 29 days for leap year
		if (month == 2) {
			var leap = (year % 4 == 0 &&
					   (year % 100 != 0 || year % 400 == 0));
			if (day>29 || (day == 29 && !leap)) {
				isValid = false;
			}
		}

	} catch  (objException){
		alert("Javascript Exception [" + this.FILE_NAME + ", " + FUNCTION_NAME + "]: " + objException + ".");
		return false;
	}
	return isValid;

}

/**
* Check if it is valid time for 12 hours basis
* @param 	int			the hour.
* @param 	int			the minute.
* @param 	int			the second.
* @return 	boolean		true: valid time, false: otherwise.

**/

function validator_js_isTime12(hour, minute, second) {

	var FUNCTION_NAME = "isTime12()";
	var isValid = true;

	try {
	// check time value with the range
		if (hour < 1 || hour > 12) {
			isValid = false;
		}
		if (day < 1 || day > 31) {
			isValid = false;
		}
		if ((month == 4 || month == 6 || month == 9 || month == 11) &&
			(day == 31)) {
			isValid = false;
		}
		if (month == 2) {
			var leap = (year % 4 == 0 &&
					   (year % 100 != 0 || year % 400 == 0));
			if (day>29 || (day == 29 && !leap)) {
				isValid = false;
			}
		}
	} catch  (objException){
		alert("Javascript Exception [" + this.FILE_NAME + ", " + FUNCTION_NAME + "]: " + objException + ".");
		return false;
	}
	return isValid;
}


/**
* Check if it is valid time for 24 hours basis
@param 	int			the hour.
@param 	int			the minute.
@param 	int			the second.
@return 	boolean		true: valid time, false: otherwise.

**/

function validator_js_isTime24(hour, minute, second) {

	var FUNCTION_NAME = "isTime24()";
	var isValid = true;

	try {
	// check time value with the range
		if (hour > 23 || hour < 0) {
			isValid =  false;
		}
		if (minute > 59 || minute < 0) {
			isValid = false;
		}
		if (second > 59 || second < 0) {
			isValid = false;
		}
	} catch  (objException){
		alert("Javascript Exception [" + this.FILE_NAME + ", " + FUNCTION_NAME + "]: " + objException + ".");
		return false;
	}
	return isValid;
}

/*
 * Check is the string match with the time pattern with specify the format
 * HH - Hour 24
 * hh - Hour 12
 * mm - MIN
 * ss - SECOND
 * a - AMPM
 *
 * @param	value		time input e.g. 12:15:17
 * @param	pattern		time patterm e.g. HH:mm:ss
 * @return	true : no error  false : invalid time format
 * @author	Cliff 07-10-04
 */
function validator_js_matchTimePattern(value, pattern) {

	var FUNCTION_NAME = "matchTimePattern()";
	var bValid = true;

	try {

		var valueTime = value;
		var timePattern = pattern;

		var HOUR24 = "HH";
		var HOUR12 = "hh";
		var MIN = "mm";
		var SECOND = "ss";
		var AMPM = "a";

		var orderHour24 = timePattern.indexOf(HOUR24);
		var orderHour12 = timePattern.indexOf(HOUR12);
		var orderMin = timePattern.indexOf(MIN);
		var orderSecond = timePattern.indexOf(SECOND);
		var orderAmPm = timePattern.indexOf(AMPM);

		if (value.length == 0 && pattern.length > 0) {
			bValid = false;
		}

		// check space support HH:mm:ss
		if (bValid && orderHour24 < orderMin && orderHour24 < orderSecond) {
			var space = valueTime.indexOf(valueTime.trim());

			if (space == orderHour24) {
				if(space != 0) {
					valueTime = valueTime.substring(space, valueTime.length);
				}
			} else {
				bValid = false;
			}
		}

		// support HH:mm:ss
		if (bValid) {
			if ((orderSecond > orderMin && orderMin > orderHour24)) {
				var iDelim1 = orderHour24 + HOUR24.length;
				var iDelim2 = orderMin + MIN.length;

				var delim1 = timePattern.substring(iDelim1, iDelim1 + 1);
				var delim2 = timePattern.substring(iDelim2, iDelim2 + 1);

				// use the regular expression to split the string as time pattern

				if (iDelim1 == orderMin && iDelim2 == orderSecond) {
					timeRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{2})$");
				} else if (iDelim1 == orderMin) {
					timeRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{2})$");
				} else if (iDelim2 == orderSecond) {
					timeRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{2})$");
				} else {
					timeRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{2})$");
				}
				var matched = timeRegexp.exec(valueTime);
				if(matched != null) {
					if (!this.isTime24(matched[1], matched[2], matched[3])) {
						bValid =  false;
					 }
				} else {
					bValid =  false;
				}
			} else {
				bValid = false;
			}
		}
	} catch  (objException){
		alert("Javascript Exception [" + this.FILE_NAME + ", " + FUNCTION_NAME + "]: " + objException + ".");
		return false;
	}
	return bValid;
}

/*
 * Check the input string whether it matches the format in DDMMYYYY
 *
 * @param	input	date input
 * @return	-1 : no error  0 : invalid date format
 */
function validator_js_isDateDDMMYYYY(input)
{
	var FUNCTION_NAME = "isDateDDMMYYYY()";
	var isValid = true;

	try {

	    //alert (input);
	    var checkstr = "0123456789";
		var temp = input;
		var DateTemp = "";
		var seperator = "/";
		var dd;
		var mm;
		var yyyy;
		var leap = 0;
		var err = 0;

	   	if(temp=="") return -1; //null, not check
	   	for (i = 0; i < temp.length; i++) {
		  	if (checkstr.indexOf(temp.substr(i,1)) >= 0) {
		    	DateTemp = DateTemp + temp.substr(i,1);
		  	}
	   	}
		// use the regular expression to split the string as time pattern
	    var filter  = /^([0-3])+([0-9])+\/([0-1])+([0-9])+\/([0-9]{4})+$/;//for dd/mm/yyyy
		if (!filter.test(temp))
	        return 0;
	    //allow 29/19/2003333
	    if (temp.length != 10)
	        return 0;
	    //allow 29/19/2003->29192003
	    dd = temp.substring(0,2);
	    mm = temp.substring(3,5);
	    yyyy = temp.substring(6,11);


	    if(DateTemp=="") return 0;
	    if (DateTemp.length != 8) err = 19;
	    yyyy = DateTemp.substr(4,4);
	    if (yyyy == 0) err = 20;
	    mm = DateTemp.substr(2,2);
	    if ((mm < 1) || (mm > 12)) err = 21;
	    dd = DateTemp.substr(0,2);
	    if (dd < 1) err = 22;
	    if ((yyyy % 4 == 0) || (yyyy % 100 == 0) || (yyyy % 400 == 0)) leap = 1;
	    if ((mm == 2) && (leap == 1) && (dd > 29)) err = 23;
	    else if ((mm == 2) && (leap != 1) && (dd > 28)) err = 24;
	    if ((dd > 31) && ((mm == "01") || (mm == "03") || (mm == "05") || (mm == "07") || (mm == "08") || (mm == "10") || (mm == "12"))) err = 25;
	    else if ((dd > 30) && ((mm == "04") || (mm == "06") || (mm == "09") || (mm == "11"))) err = 26;

	    if ((dd == 0) && (dd == 0) && (yyyy == 00)) {
	        err = 0; dd = ""; mm = ""; yyyy = ""; seperator = "";
	    }

	    if (err == 0) {
	        input.value = dd + seperator + mm + seperator + yyyy;
	    }
	    else { // day format invalid
	        isValid = false;
	    }

	} catch  (objException){
		alert("Javascript Exception [" + this.FILE_NAME + ", " + FUNCTION_NAME + "]: " + objException + ".");
		return false;
	}
	return isValid;


    return -1; //no error
}

/**
* Check if it is integer.
* @param 	sText		the input value.
* @return 	boolean		true: the input value is integer, false: otherwise.
**/

function validator_js_isInteger(sText)
{
	var FUNCTION_NAME = "isInteger()";
	var isValid = false;

	try {
		var ValidChars = "0123456789";
		var isValid=true;
		var Char;
		for (i = 0; i < sText.length && isValid == true; i++)
		{
			Char = sText.charAt(i);
			if (ValidChars.indexOf(Char) == -1)
			{
				isValid = false;
			}
		}
		if (!isValid){
			var iValue = parseInt(sText);
			if (isNaN(iValue) || !(iValue >= -2147483648 && iValue <= 2147483647)) {
				isValid = false;
			}else{
				isValid = true;
			}
		}

	} catch  (objException){
		alert("Javascript Exception [" + this.FILE_NAME + ", " + FUNCTION_NAME + "]: " + objException + ".");
		return false;
	}
	return isValid;

}

/**
* Check if it is numeric.
* @param 	sText		the input value.
* @return 	boolean		true: the input value is numeric, false: otherwise.

**/
function validator_js_isNumeric(sText)
{
	var FUNCTION_NAME = "isNumeric()";
	var isValid = true;

	try {
		var ValidChars = "0123456789.";
		var Char;
		for (i = 0; i < sText.length && isValid == true; i++)
		{
			Char = sText.charAt(i);
			if (ValidChars.indexOf(Char) == -1)
			{
				isValid = false;
			}
		}
		if (!isValid){
			var iValue = parseInt(sText);//var iValue = parseFloat(sText);??
			if (isNaN(iValue) || !(iValue >= -2147483648 && iValue <= 2147483647)) {
				isValid = false;
			}else{
				isValid = true;
			}
		}

	} catch  (objException){
		alert("Javascript Exception [" + this.FILE_NAME + ", " + FUNCTION_NAME + "]: " + objException + ".");
		return false;
	}
	return isValid;

}

/**
* Check if it is number 0-9 only
* @param 	sText		the input value.
* @return 	boolean		true: the input value is numeric, false: otherwise.

**/
function validator_js_isNumber(sText)
{
	var FUNCTION_NAME = "isNumeric()";
	var isValid = true;

	try {
		var ValidChars = "0123456789";
		var Char;
		for (i = 0; i < sText.length && isValid == true; i++)
		{
			Char = sText.charAt(i);
			if (ValidChars.indexOf(Char) == -1)
			{
				isValid = false;
			}
		}

	} catch  (objException){
		alert("Javascript Exception [" + this.FILE_NAME + ", " + FUNCTION_NAME + "]: " + objException + ".");
		return false;
	}
	return isValid;

}

/**
* Check if it is floating point.
* @param 	sText		the input value.
* @return 	boolean		true: the input value is floating point value, false: otherwise.
**/
function validator_js_isFloat(sText)
{
	//alert(sText);

	var FUNCTION_NAME = "isFloat()";
	var isValid = true;

	try {
//		Comment by Cliff on 17-03-05
//		problem solved "cannot input 0.8 or 0.9"
//    Uncomment by Ivan 30/8/2007 18:35
//		modify validator_js_isAllDigits(), solve problem on "888t to 0.0"
		if (!validator_js_isAllDigits(sText)) {
			isValid = false;
		}else {
			var iValue = parseFloat(sText);
			if (isNaN(iValue)) {
				isValid = false;
			}
		}

	} catch  (objException){
		alert("Javascript Exception [" + this.FILE_NAME + ", " + FUNCTION_NAME + "]: " + objException + ".");
		return false;
	}
	return isValid;

}

/**
* Check if it contains any non-digits and hexadecimal digits
*
* @param 	argvalue		the input value.
* @return 	boolean		true: the input value contains digit only, false: otherwise
**/
function validator_js_isAllDigits(argvalue) {

	var validChars = "0123456789";
	var startFrom = 0;
	var decimal = false;  // Ivan 30/8/2007 18:35  add 1 case for input 0.xxx

	//alert("argvalue = " + argvalue);
	argvalue = argvalue.toString();

	// Ivan 30/8/2007 18:35 add 1 case for input 0.xxx
	if (argvalue.substring(0, 2) == "0.") {
	   startFrom = 1;
	   decimal = true;
	}

	//remove '.' before check digit
	argvalue = argvalue.split('.').join('');
	//alert("argvalue = " + argvalue);

	// Ivan 30/8/2007 18:35 add 1 case for input 0.xxx
	if (decimal != true) {
		if (argvalue.substring(0, 2) == "0x") {
		   validChars = "0123456789abcdefABCDEF";
		   startFrom = 2;
		} else if (argvalue.charAt(0) == "0") {
		   validChars = "01234567";
		   startFrom = 1;
		} else if (argvalue.charAt(0) == "-") {//exclude minus sign
			startFrom = 1;
		}
	}

	for (var n = startFrom; n < argvalue.length; n++) {
		if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) return false;
	}
	return true;
}

/**
* Check if it is leap year.
* @param 	int			the year.
* @return 	boolean		true: it is leap year, false: otherwise.
**/

function validator_js_isLeapYear(y)
{
	return (new Date(y, 1, 29)).getMonth() == 1 ;
}

/**
* Check if the value is within the range from min and max.
* @param 	int			the input value.
* @param 	int			the minimum value.
* @param 	int			the maximum value.
* @return 	boolean		true: input>=min and input<=max, false: otherwise.
**/

function validator_js_isWithInRange (input, min, max) {
	return input >= min && input <=max;
}
/**
* Check if it is valid bank account number with the format ###-###-######## (For HK use)
* @param 	str			the year.
* @return 	boolean		true: it is valid bank account number, false: otherwise.
**/

function validator_js_isBankAccountNo(str)
{
	var FUNCTION_NAME = "isBankAccountNo(str)";
	var isValid = false;

	try {

		var filter = /^([0-9]{3})+-([0-9]{3})+-([0-9]{10})+$/;//for XXX-XXX-XXXXXXXXXX
		if(!filter.test(str)) {
			isValid = false;
		} else {
			isValid = true;
		}

	} catch  (objException){
		alert("Javascript Exception [" + this.FILE_NAME + ", " + FUNCTION_NAME + "]: " + objException + ".");
		return false;
	}
	return isValid;
}

/**
* Check if array1 is identical to array2.
* @param 	array		array1.
* @param 	array		array2.
* @return 	boolean		true: they are identical, false: otherwise.
**/

function validator_js_isArrayEquals(array1 , array2){
	var FUNCTION_NAME = "isArrayEquals()";
	var isEqual = false;
	try {

		if (log) {
			log.debug(array2.join(","));
			log.debug(array1.join(","));
		}
		isEqual = array1.join(",") == array2.join(",");
	} catch  (objException){
		alert("Javascript Exception [" + this.FILE_NAME + ", " + FUNCTION_NAME + "]: " + objException + ".");
		return false;
	}
	return isEqual;
}

/**
 * Do comparison for specified dates.
 * @param	date1
 * @param	date2
 * @return true if date1 > date2
 * @author	Hanna	10Apr2005
 */
function validator_js_isDateGreater(date1, date2){
	var FUNCTION_NAME = "isDateGreater()";
	var isGreater = false;
	try {
		var day1 = date1.getDate();
		var month1 = date1.getMonth();
		var year1 = date1.getFullYear();

		var day2 = date2.getDate();
		var month2 = date2.getMonth();
		var year2 = date2.getFullYear();

		isGreater = this.isDateGreater_DDMMYYYY(day1, month1, year1, day2, month2, year2);
	} catch  (objException){
		alert("Javascript Exception [" + this.FILE_NAME + ", " + FUNCTION_NAME + "]: " + objException + ".");
		return false;
	}
	return isGreater;
}

/**
 * Do comparison for specified (day1, month1, year1), (day2, month2, year2).
 * @param	day1
 * @param	month1
 * @param	year1
 * @param	day2
 * @param	month2
 * @param	year2
 * @return true if (day1, month1, year1) > (day2, month2, year2)
 * @author	Hanna	10Apr2005
 */
function validator_js_isDateGreater_DDMMYYYY(day1, month1, year1, day2, month2, year2){
	var FUNCTION_NAME = "isDateGreater_DDMMYYYY()";
	var isGreater = false;
	try {
		if ( year1 == year2){
			if ( month1 == month2){
				if (day1 >day2){
					isGreater = true;
				}
			}else if (month1 > month2 ){
				isGreater = true;
			}
		}else if (year1 > year2){
			isGreater = true;
		}
	} catch  (objException){
		alert("Javascript Exception [" + this.FILE_NAME + ", " + FUNCTION_NAME + "]: " + objException + ".");
		return false;
	}
	return isGreater;
}



/**
* Check if leap day is within the period of yearFrm/monthFrm to yearTo/monthTo
* @param	monthFrm	month from
* @param	yearFrm		year from
* @param	monthTo		month to
* @param	yearTo		year to
* @return	boolean		true: leap day is within the period; false: otherwise.

**/

function validator_js_isContainLeapDay(monthFrm, yearFrm, monthTo, yearTo){
	var FUNCTION_NAME = "validator_js_isContainLeapDay()";
	var isLeap = false;
	try {

		if ( (this.isLeapYear(yearFrm) && monthFrm<=2) || (this.isLeapYear(yearTo) && monthTo>2) ) {
			isLeap = true;
		}

	} catch  (objException){
		alert("Javascript Exception [" + this.FILE_NAME + ", " + FUNCTION_NAME + "]: " + objException + ".");
		return false;
	}
	return isLeap;
}


function validator_js_checkUid(idStr){
  var FUNCTION_NAME = "checkUid()";

  try {
	  var letters = new Array('A', 'B', 'C', 'D',
	      'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M',
	      'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
	      'X', 'Y', 'W', 'Z', 'I', 'O');
	  var multiply = new Array(1, 9, 8, 7, 6, 5,
	                           4, 3, 2, 1);
	  var nums = new Array(2);
	  var firstChar;
	  var firstNum;
	  var lastNum;
	  var total = 0;
	  var regExpID=/^[a-z](1|2)\d{8}$/i;
	  if (idStr.search(regExpID)==-1) {
	    //alert('Your ID is invalid!');
	   return false;
	  } else {
	    firstChar = idStr.charAt(0).toUpperCase();
	    lastNum = idStr.charAt(9);
	  }
	  for (var i=0; i<26; i++) {
	    if (firstChar == letters[i]) {
	      firstNum = i + 10;
	      nums[0] = Math.floor(firstNum / 10);
	      nums[1] = firstNum - (nums[0] * 10);
	      break;
	    }
	  }
	   for(var i=0; i<multiply.length; i++){
	    if (i<2) {
	      total += nums[i] * multiply[i];
	    } else {
	      total += parseInt(idStr.charAt(i-1)) *
	               multiply[i];
	    }
	  }
	  if (lastNum == 0 && (total % 10) != lastNum ){
		//alert('Your ID is wrong!!');
		return false;
	  }
	  if (lastNum != 0 && (10 - (total % 10))!= lastNum) {
		//alert('Your ID is wrong!!');
		return false;
	  }
	} catch  (objException){
		alert("Javascript Exception [" + this.FILE_NAME + ", " + FUNCTION_NAME + "]: " + objException + ".");
		return false;
	}
  return true;


}

/**
* check FileSystemObject is work
* @return	'Y' : is work; 'N' is now work
**/

function validator_js_allowFileObj() {
	var FUNCTION_NAME = "allowFileObj()";
	var testFSO;
	var isAllow = 'Y';
	try {
		oFSO = new ActiveXObject("Scripting.FileSystemObject");
	}
	catch(e) {
		isAllow = 'N';
		if(e.number != -2146827859) {
			alert("Javascript Exception [" + this.FILE_NAME + ", " + FUNCTION_NAME + "]: " + objException + ".");
		}
	}
	testFSO = null;
	return isAllow;
}

    /***************************************************************
        Private Constant
    ****************************************************************/

Validator.prototype.FILE_NAME="Validator.js";


    /***************************************************************
        Private methods
    ****************************************************************/



